package com.liuhouse.pojo;

import com.baomidou.mybatisplus.annotation.*;

import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * <p>
 * 文章表
 * </p>
 *
 * @author liuhouse
 * @since 2024-01-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sg_article")
@ApiModel(value="Article对象", description="文章表")
@AllArgsConstructor
@NoArgsConstructor
public class Article implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "标题")
    @TableField("title")
    private String title;

    @ApiModelProperty(value = "文章内容")
    @TableField("content")
    private String content;

    @ApiModelProperty(value = "文章摘要")
    @TableField("summary")
    private String summary;

    @ApiModelProperty(value = "所属分类id")
    @TableField("category_id")
    private Long categoryId;

    //增加一个字段,为categoryName，由categoryId查询出来
    //由于数据库没有category_name字段,所以要注解置顶一下字段是非数据库字段
    @TableField(exist = false)//代表这个字段在数据库中不存在,避免MybatisPlus查询的时候报错
    private String categoryName;

    @ApiModelProperty(value = "缩略图")
    @TableField("thumbnail")
    private String thumbnail;

    @ApiModelProperty(value = "是否置顶（0否，1是）")
    @TableField("is_top")
    private String isTop;

    @ApiModelProperty(value = "状态（0已发布，1草稿）")
    @TableField("status")
    private String status;

    @ApiModelProperty(value = "访问量")
    @TableField("view_count")
    private Long viewCount;

    @ApiModelProperty(value = "是否允许评论 1是，0否")
    @TableField("is_comment")
    private String isComment;

    @TableField(value = "create_by" , fill = FieldFill.INSERT)
    private Long createBy;

    @TableField(value = "create_time" , fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @TableField(value = "update_by")
    private Long updateBy;

    @TableField(value = "update_time" , fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "删除标志（0代表未删除，1代表已删除）")
    @TableField("del_flag")
    private Integer delFlag;


    //把redis的浏览连数据更新到mysql数据库
    public Article(Long id, Long viewCount) {
        this.id = id;
        this.viewCount = viewCount;
    }
}
